package com.woniuxy.springboot.mybatis.execption;

import org.springframework.web.bind.annotation.ExceptionHandler;

import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionUtils {
    public static String getMessage(Exception e){
        StringWriter strWriter=null;
        PrintWriter printWriter=null;
        try {
            strWriter = new StringWriter();
            printWriter = new PrintWriter(strWriter);
            e.printStackTrace(printWriter);
            strWriter.flush();
            printWriter.flush();
        }finally {
            if(printWriter!=null){
                printWriter.close();
            }
            if(strWriter!=null){
                try {
                    strWriter.close();
                }catch (Exception e1){
                    e1.printStackTrace();
                }
            }
        }
        return strWriter.toString();
    }
}
